﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ViewModels="clr-namespace:ScrumSprintMonitor.Modules.WorkItemMonitor.ViewModels"
    xmlns:MonitorWindow="clr-namespace:ScrumSprintMonitor.UI.Wpf.Views.MonitorWindow;assembly=ScrumSprintMonitor.UI.Wpf"
    xmlns:converters="clr-namespace:ScrumSprintMonitor.UI.Wpf.Converters;assembly=ScrumSprintMonitor.UI.Wpf"
    xmlns:Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero">

    <converters:RelativeMarginConverter x:Key="RelativeMarginConverter" />

    <Style x:Key="GlowOnUpdateStyle" TargetType="{x:Type FrameworkElement}">
        <Setter Property="Opacity" Value="0" />

        <Style.Triggers>
            <DataTrigger Binding="{Binding RecentlyUpdated}" Value="True">
                <DataTrigger.EnterActions>
                    <BeginStoryboard Name="GlowStoryboard">
                        <Storyboard>
                            <!-- Animate the Opacity to 1 over two seconds. -->
                            <DoubleAnimation BeginTime="00:00:04" Duration="00:00:02" Storyboard.TargetProperty="Opacity" To="1" />
                            <DoubleAnimation BeginTime="00:00:07" AutoReverse="True" RepeatBehavior="Forever" Duration="00:00:02" Storyboard.TargetProperty="Opacity" To="0.2" />
                        </Storyboard>
                    </BeginStoryboard>
                </DataTrigger.EnterActions>
                <DataTrigger.ExitActions>
                    <StopStoryboard BeginStoryboardName="GlowStoryboard" />

                    <BeginStoryboard>
                        <Storyboard>
                            <!-- Animate the Opacity to 0 over five seconds. -->
                            <DoubleAnimation Duration="00:00:02" Storyboard.TargetProperty="Opacity" To="0"/>
                        </Storyboard>
                    </BeginStoryboard>
                </DataTrigger.ExitActions>
            </DataTrigger>
        </Style.Triggers>
    </Style>

    <DataTemplate DataType="{x:Type ViewModels:TeamMemberViewModel}">
        <Viewbox>
            <Themes:SystemDropShadowChrome CornerRadius="2,32,2,32">
                <Grid x:Name="TeamBadgeHostArea">
                    <!--Compensate for the proportional margin given to the ViewBox below to align the content with the glow-on-update image-->
                    <Grid.Margin>
                        <MultiBinding Converter="{StaticResource RelativeMarginConverter}" ConverterParameter="-6,-10,-6,-10">
                            <Binding ElementName="TeamBadgeHostArea" Path="ActualHeight" />
                            <Binding ElementName="TeamBadgeHostArea" Path="ActualWidth" />
                        </MultiBinding>
                    </Grid.Margin>

                    <!-- Glow-on-update element -->
                    <Grid>
                        <Grid.Style>
                            <Style TargetType="Grid">
                                <Setter Property="Opacity" Value="1" />

                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding IsActiveInSprint}" Value="False">
                                        <Setter Property="Opacity" Value="0.25" />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Grid.Style>

                        <Image x:Name="Glow" Source="Glow.png" Stretch="Fill" Style="{StaticResource GlowOnUpdateStyle}" />
                    </Grid>

                    <ContentPresenter Content="{Binding}">
                        <!--Add a proportional margin to align the content with the glow-on-update image-->
                        <ContentPresenter.Margin>
                            <MultiBinding Converter="{StaticResource RelativeMarginConverter}" ConverterParameter="6,10,6,10">
                                <Binding ElementName="TeamBadgeHostArea" Path="ActualHeight" />
                                <Binding ElementName="TeamBadgeHostArea" Path="ActualWidth" />
                            </MultiBinding>
                        </ContentPresenter.Margin>

                        <ContentPresenter.Style>
                            <Style TargetType="{x:Type ContentPresenter}">
                                <Setter Property="ContentTemplate">
                                    <Setter.Value>
                                        <DataTemplate>
                                            <MonitorWindow:TeamMemberBadge/>
                                        </DataTemplate>
                                    </Setter.Value>
                                </Setter>

                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding Path=Unassigned}" Value="True">
                                        <Setter Property="ContentTemplate">
                                            <Setter.Value>
                                                <DataTemplate>
                                                    <MonitorWindow:UnassignedTeamMemberBadge />
                                                </DataTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </ContentPresenter.Style>
                    </ContentPresenter>
                </Grid>
            </Themes:SystemDropShadowChrome>
        </Viewbox>
    </DataTemplate>
</ResourceDictionary>